package com.gimi.cloud.bbp.client.controller.userInfo;

import com.gimi.cloud.bbp.client.service.userInfo.WorkInfoService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.userInfo.RdWorkInfoDTO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户配送信息管理
 * @author chendi
 * @date 2018年1月8日
 */
@RestController
@RequestMapping(value = "workInfo")
public class workInfoController {

    @Autowired
    private WorkInfoService workInfoService;
    
    /**
     * 新添加user工作信息
     * @param rdExpressInfoDTO
     * @param response
     */
    @RequestMapping(value = "/add")
    public void addWorkInfo(@RequestBody RdWorkInfoDTO workInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        workInfoService.addWorkInfo(workInfoDTO);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }   
    /** 
     * 根据info_id查询user工作信息
     */
    @RequestMapping(value = "/single")
    public void workInfoSingle(@RequestBody RdWorkInfoDTO workInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        RdWorkInfoDTO workInfoSingle = workInfoService.getWorkInfoSingle(workInfoDTO);
        resp.setRes_data(workInfoSingle);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    /**
     * 更新配送信息
     * @param userInfoDTO
     * @param response
     */
    @RequestMapping(value = "/update")
    public void updateWorkInfo(@RequestBody RdWorkInfoDTO workInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        workInfoService.updateWorkInfo(workInfoDTO);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
    /**
     * 删除单条信息(假删除)
     */
    @RequestMapping(value = "/delete")
    public void delWorkInfo(@RequestBody RdWorkInfoDTO workInfoDTO, HttpServletResponse response) {
        Response resp = new Response();
        workInfoService.deleteWorkInfo(workInfoDTO);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
}
